<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>快速排序</title>
	</head>
	<body>
		<script>
			let arr = [49,38,65,97,76,13,27,49];
			function quicksort(arr, low, high) {
				// debugger
				if (low < high) {
					let pivotpos = partition(arr, low, high);
					quicksort(arr, low, pivotpos - 1);
					quicksort(arr, pivotpos + 1, high);
				} else {
					console.log(arr);
				}
			}
			function partition(arr, low, high) {
				// debugger
				let pivotpos = arr[low];
				while (low < high) {
					while (low < high && pivotpos <= arr[high]) {
						--high
					}
					arr[low] = arr[high]
					while (low < high && pivotpos >= arr[low]) {
						++low
					}
					arr[high] = arr[low]
				}
				arr[high] = pivotpos;
				return low
			}
			quicksort(arr,0,arr.length-1);
		</script>
	</body>
</html>
